#include "include.h"

#if BT_SCO_MAV_EN
//魔音化
static s16  buf_01[1536]  AT(.mavsco_buf);
static s16  buf_02[128]   AT(.mavsco_buf);
static s16  buf_03[128]   AT(.mavsco_buf);
static s16  buf_04[512]   AT(.mavsco_buf);
static s16  buf_05[64]    AT(.mavsco_buf);
static s16  buf_06[64]    AT(.mavsco_buf);
static char buf_07[512]   AT(.mavsco_buf);

typedef struct {
    u8 res[2];
    s16 *buf_used;
    s16 *inbuf;
    s16 *outbuf;
    s16 *cache;
    s16 *mav_out;
    s16 *out1_buf;
    char *s8_fdata;
}mav_cfg_test;

mav_cfg_test mav_cfg_te = {
    .res[0]         = 0,
    .res[1]         = 0,
    .buf_used           = buf_01,
    .inbuf              = buf_02,
    .outbuf             = buf_03,
    .cache              = buf_04,
    .mav_out            = buf_05,
    .out1_buf           = buf_06,
    .s8_fdata           = buf_07,
};

void mav_kick_start(void);
void magic_voice_init(void *cfg);
void magic_voice_set_level(u8 type, u8 level);

AT(.rodata.magic)
const u8 magic_table[4][2] = {
    {0, 5},
    {0, 2},
    {1, 1},
    {1, 4},
};

///切换魔音
void bt_sco_magic_voice_switch(void)
{
    //设置魔音级别
    u8 magic_type,magic_level;
    static int magic_sel_ce = 0;
    magic_sel_ce++;
    if (magic_sel_ce > 4) {
        magic_sel_ce = 0;
    }
    if (!magic_sel_ce) {
        magic_type = 0;
        magic_level = 0;
    } else {
        magic_type = magic_table[magic_sel_ce - 1][0];
        magic_level = magic_table[magic_sel_ce - 1][1];
    }
    magic_voice_set_level(magic_type, magic_level);
//    printf("MAGIC VOICE ---> (%d)\n", magic_sel_ce);
}

AT(.com_text.mav)
void bt_sco_mav_process(u8 *ptr, u32 samples)
{
    if (samples == 128) {
        memcpy(mav_cfg_te.inbuf, ptr, 256);
        memcpy(ptr, mav_cfg_te.outbuf, 256);
        mav_kick_start();
    }
}

///魔音初始化
void bt_sco_magic_init(void)
{
    magic_voice_init(&mav_cfg_te);
}
#else
AT(.com_text.mav)
void bt_sco_mav_process(u8 *ptr, u32 samples){};

#endif // BT_SCO_MAV_EN
